﻿Imports System.Windows.Forms
Imports System.Drawing

Namespace ControlLibrary

    Public Class dbiWSFSchedule

#Region "**Classes**"
        ''' <summary>A public class used in the hittest method to return various items at the current mouse coordinates.</summary>
        Public Class HitTestResults
            Inherits System.EventArgs
            Private l_ScheduleItem As Dbi.WinControl.Schedule.dbiScheduleItem
            Private l_TimeBarItems As New System.Collections.Generic.List(Of Dbi.WinControl.Schedule.dbiTimeBarItem)
            Private l_CustomAreas As New System.Collections.Generic.List(Of Dbi.PIM.dbiCustomArea)
            Private l_DateTimeAt As Date
            Private l_OverRuler As Boolean
            Private l_OverList As Boolean
            Private l_ItemIsHeader As Boolean
            Private l_DisplayContextMenu As Boolean = True

            ''' <summary>The dbiSchedule Item the mouse is currently over. Set to nothing if not currently over an item.</summary>
            Public Property ScheduleItem() As Dbi.WinControl.Schedule.dbiScheduleItem
                Get
                    Return l_ScheduleItem
                End Get
                Set(ByVal value As Dbi.WinControl.Schedule.dbiScheduleItem)
                    l_ScheduleItem = value
                End Set
            End Property

            ''' <summary>A collection of dbiSchedule TimeBar Items (Shipments) at the current mouse position. Empty if none.</summary>
            Public Property TimeBarItems() As System.Collections.Generic.List(Of Dbi.WinControl.Schedule.dbiTimeBarItem)
                Get
                    Return l_TimeBarItems
                End Get
                Set(ByVal value As System.Collections.Generic.List(Of Dbi.WinControl.Schedule.dbiTimeBarItem))
                    l_TimeBarItems = value
                End Set
            End Property

            ''' <summary>A collection of dbiSchedule CustomAreas (Exceptions) at the current mouse position. Empty if none.</summary>
            Public Property CustomAreas() As System.Collections.Generic.List(Of Dbi.PIM.dbiCustomArea)
                Get
                    Return l_CustomAreas
                End Get
                Set(ByVal value As System.Collections.Generic.List(Of Dbi.PIM.dbiCustomArea))
                    l_CustomAreas = value
                End Set
            End Property

            ''' <summary>The datetime at the current mouse position.</summary>
            Public Property DateTimeAt() As Date
                Get
                    Return l_DateTimeAt
                End Get
                Set(ByVal value As Date)
                    l_DateTimeAt = value
                End Set
            End Property

            ''' <summary>A boolean value indicating if the mouse is currently over the dbiSchedule ruler area.</summary>
            Public Property OverRuler() As Boolean
                Get
                    Return l_OverRuler
                End Get
                Set(ByVal value As Boolean)
                    l_OverRuler = value
                End Set
            End Property

            ''' <summary>A boolean value indicating if the mouse is currently over the dbiSchedule list area.</summary>
            Public Property OverList() As Boolean
                Get
                    Return l_OverList
                End Get
                Set(ByVal value As Boolean)
                    l_OverList = value
                End Set
            End Property

            ''' <summary>A boolean value indicating if the current item the mouse is over is a header (Warehouse) item.</summary>
            Public Property ItemIsHeader() As Boolean
                Get
                    Return l_ItemIsHeader
                End Get
                Set(ByVal value As Boolean)
                    l_ItemIsHeader = value
                End Set
            End Property

            ''' <summary>A boolean value indicating if the context menu should be displayed.</summary>
            Public Property DisplayMenu() As Boolean
                Get
                    Return l_DisplayContextMenu
                End Get
                Set(ByVal value As Boolean)
                    l_DisplayContextMenu = value
                End Set
            End Property

        End Class

        ''' <summary>A public class used to pass Schedule arguments to the dbiWSFSchedule raised events.</summary>
        Public Class ScheduleArgs
            Inherits System.EventArgs

            Private l_argWSFObject As dbiWSF.FrameworkObjects.objWSFObjects
            Private l_argWarehouse As dbiWSF.FrameworkObjects.objWarehouse
            Private l_argLoadingDock As dbiWSF.FrameworkObjects.objLoadingDock
            Private l_argShipment As dbiWSF.FrameworkObjects.objShipment
            Private l_argOrderHeader As dbiWSF.FrameworkObjects.objOrderHeader
            Private l_argOrderDetail As dbiWSF.FrameworkObjects.objOrderDetail
            Private l_argRecurrence As dbiWSF.FrameworkObjects.objRecurrence
            Private l_argException As dbiWSF.FrameworkObjects.objLoadingDockException

            Private l_argDbiTimebar As Dbi.WinControl.Schedule.dbiTimeBarItem
            Private l_argDbiSchedItem As Dbi.WinControl.Schedule.dbiScheduleItem

            Private l_argOrigStart As Date
            Private l_argOrigEnd As Date


            Private l_Allow As Boolean = True

            ''' <summary>The MainWSFObject in use.</summary>
            Public Property argWSFObject() As dbiWSF.FrameworkObjects.objWSFObjects
                Get
                    Return l_argWSFObject
                End Get
                Set(ByVal value As dbiWSF.FrameworkObjects.objWSFObjects)
                    l_argWSFObject = value
                End Set
            End Property

            ''' <summary>The warehouse being affected.</summary>
            Public Property argWarehouse() As dbiWSF.FrameworkObjects.objWarehouse
                Get
                    Return l_argWarehouse
                End Get
                Set(ByVal value As dbiWSF.FrameworkObjects.objWarehouse)
                    l_argWarehouse = value
                End Set
            End Property

            ''' <summary>The loading dock being affected.</summary>
            Public Property argLoadingDock() As dbiWSF.FrameworkObjects.objLoadingDock
                Get
                    Return l_argLoadingDock
                End Get
                Set(ByVal value As dbiWSF.FrameworkObjects.objLoadingDock)
                    l_argLoadingDock = value
                End Set
            End Property

            ''' <summary>The shipment being affected.</summary>
            Public Property argShipment() As dbiWSF.FrameworkObjects.objShipment
                Get
                    Return l_argShipment
                End Get
                Set(ByVal value As dbiWSF.FrameworkObjects.objShipment)
                    l_argShipment = value
                End Set
            End Property

            ''' <summary>The orderheader being affected.</summary>
            Public Property argOrderHeader() As dbiWSF.FrameworkObjects.objOrderHeader
                Get
                    Return l_argOrderHeader
                End Get
                Set(ByVal value As dbiWSF.FrameworkObjects.objOrderHeader)
                    l_argOrderHeader = value
                End Set
            End Property

            ''' <summary>The orderdetail being affected.</summary>
            Public Property argOrderDetail() As dbiWSF.FrameworkObjects.objOrderDetail
                Get
                    Return l_argOrderDetail
                End Get
                Set(ByVal value As dbiWSF.FrameworkObjects.objOrderDetail)
                    l_argOrderDetail = value
                End Set
            End Property

            ''' <summary>The recurrence being affected.</summary>
            Public Property argRecurrence() As dbiWSF.FrameworkObjects.objRecurrence
                Get
                    Return l_argRecurrence
                End Get
                Set(ByVal value As dbiWSF.FrameworkObjects.objRecurrence)
                    l_argRecurrence = value
                End Set
            End Property

            ''' <summary>The exception being affected.</summary>
            Public Property argException() As dbiWSF.FrameworkObjects.objLoadingDockException
                Get
                    Return l_argException
                End Get
                Set(ByVal value As dbiWSF.FrameworkObjects.objLoadingDockException)
                    l_argException = value
                End Set
            End Property

            ''' <summary>The dbiTimebar being affected.</summary>
            Public Property argDbiTimebar() As Dbi.WinControl.Schedule.dbiTimeBarItem
                Get
                    Return l_argDbiTimebar
                End Get
                Set(ByVal value As Dbi.WinControl.Schedule.dbiTimeBarItem)
                    l_argDbiTimebar = value
                End Set
            End Property

            ''' <summary>The dbiScheduleItem being affected.</summary>
            Public Property argDbiSchedItem() As Dbi.WinControl.Schedule.dbiScheduleItem
                Get
                    Return l_argDbiSchedItem
                End Get
                Set(ByVal value As Dbi.WinControl.Schedule.dbiScheduleItem)
                    l_argDbiSchedItem = value
                End Set
            End Property

            ''' <summary>The original start date of the item affected.</summary>
            Public Property argOrigStart() As Date
                Get
                    Return l_argOrigStart
                End Get
                Set(ByVal value As Date)
                    l_argOrigStart = value
                End Set
            End Property

            ''' <summary>The original end date of the item affected.</summary>
            Public Property argOrigEnd() As Date
                Get
                    Return l_argOrigEnd
                End Get
                Set(ByVal value As Date)
                    l_argOrigEnd = value
                End Set
            End Property

            ''' <summary>A boolean to indicate if the change is allowed.</summary>
            Public Property Allow() As Boolean
                Get
                    Return l_Allow
                End Get
                Set(ByVal value As Boolean)
                    l_Allow = value
                End Set
            End Property

        End Class

        ''' <summary>A public class that inherits and extends the ScheduleArgs class for moving shipments.</summary>
        Public Class ScheduleArgsShipmentMove
            Inherits ScheduleArgs
            Private l_argShipmentLoadingDockTransferTo As dbiWSF.FrameworkObjects.objLoadingDock
            Private l_argIsShipmentLoadingDockTransfer As Boolean
            Private l_argDbiSchedItemTo As Dbi.WinControl.Schedule.dbiScheduleItem

            ''' <summary>The loading dock a shipment has been moved to (if dbiScheduleMain.AllowVertMoves = true)</summary>
            Public Property argShipmentLoadingDockTransferTo() As dbiWSF.FrameworkObjects.objLoadingDock
                Get
                    Return l_argShipmentLoadingDockTransferTo
                End Get
                Set(ByVal value As dbiWSF.FrameworkObjects.objLoadingDock)
                    l_argShipmentLoadingDockTransferTo = value
                End Set
            End Property

            ''' <summary>A boolean value indicating if the shipment was actually moved to another loadingdock.</summary>
            Public Property argIsShipmentLoadingDockTransfer() As Boolean
                Get
                    Return l_argIsShipmentLoadingDockTransfer
                End Get
                Set(ByVal value As Boolean)
                    l_argIsShipmentLoadingDockTransfer = value
                End Set
            End Property

            ''' <summary>The dbiScheduleItem that the dbiTimebar was moved to.</summary>
            Public Property argDbiSchedItemTo() As Dbi.WinControl.Schedule.dbiScheduleItem
                Get
                    Return l_argDbiSchedItemTo
                End Get
                Set(ByVal value As Dbi.WinControl.Schedule.dbiScheduleItem)
                    l_argDbiSchedItemTo = value
                End Set
            End Property
        End Class

        ''' <summary>A public class for use with the filter method.</summary>
        Public Class dbiColorInfo
            Private l_BackColor As System.Drawing.Color
            Private l_BackColorTo As System.Drawing.Color
            Private l_FillType As Dbi.enumFillType

            Public Property BackColor() As System.Drawing.Color
                Get
                    Return l_BackColor
                End Get
                Set(ByVal value As System.Drawing.Color)
                    l_BackColor = value
                End Set
            End Property
            Public Property BackColorTo() As System.Drawing.Color
                Get
                    Return l_BackColorTo
                End Get
                Set(ByVal value As System.Drawing.Color)
                    l_BackColorTo = value
                End Set
            End Property
            Public Property FillType() As Dbi.enumFillType
                Get
                    Return l_FillType
                End Get
                Set(ByVal value As Dbi.enumFillType)
                    l_FillType = value
                End Set
            End Property

            Public Sub New(ByVal curItem As Dbi.WinControl.Schedule.dbiScheduleItem)
                Me.BackColor = curItem.BackColor
                Me.BackColorTo = curItem.BackColorTo
                Me.FillType = curItem.FillType
            End Sub
        End Class
#End Region

#Region "**Public Enums**"
        Public Enum ScheduleViews
            Daily05MinHourlyView = 0
            Daily10MinHourlyView = 1
            Daily15MinHourlyView = 2
            Daily30MinHourlyView = 3
            Daily60MinHourlyView = 4
            Weekly1DayWeeklyView = 5
            Monthly1WeekMonthView = 6
            Yearly1MonthYearView = 7
        End Enum
#End Region

#Region "**Public Events**"
        Public Event SchedClick(ByVal sender As Object, ByVal mouseArgs As System.Windows.Forms.MouseEventArgs, ByVal HitTest As HitTestResults)

        Public Event clShipmentBeforeAdd(ByVal sender As Object, ByVal e As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs)
        Public Event clShipmentBeforeChange(ByVal sender As Object, ByVal e As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgsShipmentMove)
        Public Event clShipmentBeforeRemove(ByVal sender As Object, ByVal e As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs)

        Public Event clShipmentAfterAdd(ByVal sender As Object, ByVal e As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs)
        Public Event clShipmentAfterChange(ByVal sender As Object, ByVal e As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgsShipmentMove)
        Public Event clShipmentAfterRemove(ByVal sender As Object, ByVal e As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs)

        Public Event clShipmentDoubleClick(ByVal sender As Object, ByVal e As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs)
        Public Event clLoadingDockClick(ByVal sender As Object, ByVal e As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs)
        Public Event clWarehouseClick(ByVal sender As Object, ByVal e As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs)
        Public Event clWarehouseDoubleClick(ByVal sender As Object, ByVal e As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs)
        Public Event clLoadingDockDoubleClick(ByVal sender As Object, ByVal e As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs)

        Public Event clTitleOver(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

        Public Event clUserDrawnBar(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.UserDrawnBarEventArgs)
        Public Event clUserDrawnFooter(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.UserDrawnFooterEventArgs)
        Public Event clUserDrawnHeader(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.UserDrawnHeaderEventArgs)
        Public Event clUserDrawnLine(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.UserDrawnLineEventArgs)

        Public Event clBeforeTimeBarDrop(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.BeforeTimeBarDropEventArgs)
        Public Event clAfterTimeBarDrop(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.AfterTimeBarDropEventArgs)
        Public Event clDropList(ByVal sender As Object, ByVal e As Dbi.WinControl.DropListEventArgs)

        Public Event clValuePoint(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.ValuePointEventArgs)
#End Region

#Region "**Global Variables**"
        Private g_ScheduleItemOver As Dbi.WinControl.Schedule.dbiScheduleItem
        Private g_CursorPos As New System.Drawing.Point
        Private g_OverTimebar As Boolean

        Private g_OverTitleTipDisplay As Boolean

        Private g_BusinessRulesDialog As dbiWSF.Dialogs.dlgBusinessRule
        Private g_EventArg As Object
        Private g_EventArgMethod As dbiWSF.Dialogs.EventMethods

        Private g_IsFiltered As Boolean = False
        Private g_ItemOrigColor As New System.Collections.Generic.Dictionary(Of System.Guid, dbiColorInfo)

        Private g_LoadDockColorCargoMatch As System.Drawing.Color = Color.FromArgb(221, 242, 204) 'Lightish Green
        Private g_LoadDockColorPartialCargoMatch As System.Drawing.Color = Color.FromArgb(252, 246, 189) 'Lightish Yellow
        Private g_LoadDockColorNoCargoMatch As System.Drawing.Color = Color.FromArgb(254, 211, 204) 'Lightish Red#End Region
#End Region

#Region "**Local Variables**"
        Private l_SchedItemsExpanded As New System.Collections.Generic.List(Of Guid)
        Private l_SelectedWarehouseGuids As New System.Collections.Generic.List(Of Guid)
        Private l_SelectedLoadingDockGuids As New System.Collections.Generic.List(Of Guid)
        Private l_TipsOnTimebarOver As Boolean
        Private l_TipsOnTitleOver As Boolean
        Private l_OutboundShipmentColor As System.Drawing.Color = Color.LightGray

        Private l_SchedStartDate As Date
        Private l_SchedEndDate As Date

        Private l_MainWSFObjects As dbiWSF.FrameworkObjects.objWSFObjects
        Private l_MainBusinessRules As dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects

        Private l_BusinessRulesOnShipmentAdd As Boolean = True
        Private l_BusinessRulesOnShipmentChange As Boolean = True
        Private l_BusinessRulesOnShipmentRemove As Boolean = True

        Private l_ExceptionColor As Color = Color.IndianRed
        Private l_RecurrenceDailyColor As Color = Color.Tan
        Private l_RecurrenceWeeklyColor As Color = Color.Tan
        Private l_RecurrenceMonthlyColor As Color = Color.Tan
        Private l_RecurrenceCustomColor As Color = Color.Tan

        Private WithEvents l_dbiSchedContextMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu

        Private l_ScheduleView As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleViews = ScheduleViews.Daily15MinHourlyView
        'StartViewTime is minutes past midnight where you want to view to scroll to, this used for all minute types (8am * 60minutes)
        Private StartViewTime As Long = 8 * 60

        'EndViewTime is minutes past midnight where the end of the view will fit, this is used for all minute types (6pm (18) * 60minutes)
        Private EndViewTime As Long = 18 * 60
#End Region

#Region "**Public Properties**"
        ''' <summary>
        ''' Display tips when over a Shipment (dbi.wincontrol.schedule.dbiTimebarItem)
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Tips"), _
        System.ComponentModel.Description("Display tips when over a Shipment (dbi.wincontrol.schedule.dbiTimebarItem)")> _
        Public Property TipsOnTimebarOver() As Boolean
            Get
                Return l_TipsOnTimebarOver
            End Get
            Set(ByVal value As Boolean)
                l_TipsOnTimebarOver = value
            End Set
        End Property

        ''' <summary>
        ''' Display tips when over the title area of the dbiWSFSchedule
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Tips"), _
        System.ComponentModel.Description("Display tips when over the title area of the dbiWSFSchedule")> _
        Public Property TipsOnTitleOver() As Boolean
            Get
                Return l_TipsOnTitleOver
            End Get
            Set(ByVal value As Boolean)
                l_TipsOnTitleOver = value
            End Set
        End Property

        ''' <summary>
        ''' A reference to the main dbiWSF object in the project.
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Objects"), _
        System.ComponentModel.Description("A reference to the main dbiWSF object in the project."), _
        System.ComponentModel.Browsable(False)> _
        Public Property MainWSFObjects() As dbiWSF.FrameworkObjects.objWSFObjects
            Get
                Return l_MainWSFObjects
            End Get
            Set(ByVal value As dbiWSF.FrameworkObjects.objWSFObjects)
                l_MainWSFObjects = value
            End Set
        End Property

        ''' <summary>
        ''' A reference to the main BusinessRules object in the project
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Objects"), _
        System.ComponentModel.Description("A reference to the main BusinessRules object in the project"), _
        System.ComponentModel.Browsable(False)> _
        Public Property MainBusinessRules() As dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects
            Get
                Return l_MainBusinessRules
            End Get
            Set(ByVal value As dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects)
                l_MainBusinessRules = value
            End Set
        End Property

        ''' <summary>
        ''' Use BusinessRules when adding a shipment
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Business Rules"), _
        System.ComponentModel.Description("Use BusinessRules when adding a shipment")> _
        Public Property BusinessRulesOnShipmentAdd() As Boolean
            Get
                Return l_BusinessRulesOnShipmentAdd
            End Get
            Set(ByVal value As Boolean)
                l_BusinessRulesOnShipmentAdd = value
            End Set
        End Property

        ''' <summary>
        ''' Use BusinessRules when changing a shipment
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Business Rules"), _
        System.ComponentModel.Description("Use BusinessRules when changing a shipment")> _
        Public Property BusinessRulesOnShipmentChange() As Boolean
            Get
                Return l_BusinessRulesOnShipmentChange
            End Get
            Set(ByVal value As Boolean)
                l_BusinessRulesOnShipmentChange = value
            End Set
        End Property

        ''' <summary>
        ''' Use BusinessRules when removing a shipment.
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Business Rules"), _
        System.ComponentModel.Description("Use BusinessRules when removing a shipment.")> _
        Public Property BusinessRulesOnShipmentRemove() As Boolean
            Get
                Return l_BusinessRulesOnShipmentRemove
            End Get
            Set(ByVal value As Boolean)
                l_BusinessRulesOnShipmentRemove = value
            End Set
        End Property

        ''' <summary>
        ''' The current schedule view applied to the dbiWSFSchedule control
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Schedule"), _
        System.ComponentModel.Description("The current schedule view applied to the dbiWSFSchedule control")> _
        Public Property ScheduleView() As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleViews
            Get
                Return l_ScheduleView
            End Get
            Set(ByVal value As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleViews)
                l_ScheduleView = value
                'TODO: Call SetSchedView with value
            End Set
        End Property

        ''' <summary>
        ''' An attached dbiWSF context menu to use with the dbiWSFSchedule control
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Objects"), _
        System.ComponentModel.Description("An attached dbiWSF context menu to use with the dbiWSFSchedule control")> _
        Public Property dbiSchedContextMenu() As dbiWSF.ControlLibrary.dbiWSFObjectMenu
            Get
                Return l_dbiSchedContextMenu
            End Get
            Set(ByVal value As dbiWSF.ControlLibrary.dbiWSFObjectMenu)
                l_dbiSchedContextMenu = value
            End Set
        End Property

        ''' <summary>
        ''' The primary color to use for dbiWSF Exceptions
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Schedule"), _
        System.ComponentModel.Description("The primary color to use for dbiWSF Exceptions")> _
        Public Property ExceptionColor() As Color
            Get
                Return l_ExceptionColor
            End Get
            Set(ByVal value As Color)
                l_ExceptionColor = value
            End Set
        End Property

        ''' <summary>
        ''' The primary color to use for dbiWSF Exception Recurrences - Daily
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Schedule"), _
        System.ComponentModel.Description("The primary color to use for dbiWSF Exception Recurrences - Daily")> _
        Public Property RecurrenceDailyColor() As Color
            Get
                Return l_RecurrenceDailyColor
            End Get
            Set(ByVal value As Color)
                l_RecurrenceDailyColor = value
            End Set
        End Property

        ''' <summary>
        ''' The primary color to use for dbiWSF Exception Recurrences - Weekly
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Schedule"), _
        System.ComponentModel.Description("The primary color to use for dbiWSF Exception Recurrences - Weekly")> _
        Public Property RecurrenceWeeklyColor() As Color
            Get
                Return l_RecurrenceWeeklyColor
            End Get
            Set(ByVal value As Color)
                l_RecurrenceWeeklyColor = value
            End Set
        End Property

        ''' <summary>
        ''' The primary color to use for dbiWSF Exception Recurrences - Monthly
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Schedule"), _
        System.ComponentModel.Description("The primary color to use for dbiWSF Exception Recurrences - Monthly")> _
        Public Property RecurrenceMonthlyColor() As Color
            Get
                Return l_RecurrenceMonthlyColor
            End Get
            Set(ByVal value As Color)
                l_RecurrenceMonthlyColor = value
            End Set
        End Property

        ''' <summary>
        ''' The primary color to use for dbiWSF Exception Recurrences - Custom
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Schedule"), _
        System.ComponentModel.Description("The primary color to use for dbiWSF Exception Recurrences - Custom")> _
        Public Property RecurrenceCustomColor() As Color
            Get
                Return l_RecurrenceCustomColor
            End Get
            Set(ByVal value As Color)
                l_RecurrenceCustomColor = value
            End Set
        End Property

        ''' <summary>
        ''' The secondary color to use for dbiWSF Outbound Shipments
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Schedule"), _
        System.ComponentModel.Description("The secondary color to use for dbiWSF Outbound Shipments")> _
        Public Property OutboundShipmentColor() As System.Drawing.Color
            Get
                Return l_OutboundShipmentColor
            End Get
            Set(ByVal value As System.Drawing.Color)
                l_OutboundShipmentColor = value
            End Set
        End Property

        ''' <summary>
        ''' ReadOnly: Returns the start date/time of the main schedule object
        ''' </summary>
        ''' <value>Date</value>
        ''' <returns></returns>
        ''' <remarks>This is a readonly property, in order to set this value
        ''' you must use the SetMainObjects method.</remarks>
        <System.ComponentModel.Category("dbiWSF Schedule"), _
        System.ComponentModel.Description("ReadOnly: Returns the start date/time of the main schedule object")> _
        Public ReadOnly Property SchedStartDate() As Date
            Get
                Return l_SchedStartDate
            End Get
        End Property

        ''' <summary>
        ''' ReadOnly: Returns the end date/time of the main schedule object
        ''' </summary>
        ''' <value>Date</value>
        ''' <returns></returns>
        ''' <remarks>This is a readonly property, in order to set this value
        ''' you must use the SetMainObjects method.</remarks>
        <System.ComponentModel.Category("dbiWSF Schedule"), _
        System.ComponentModel.Description("ReadOnly: Returns the end date/time of the main schedule object")> _
        Public ReadOnly Property SchedEndDate() As Date
            Get
                Return l_SchedEndDate
            End Get
        End Property
#End Region

#Region "**dbiWSFSchedule Control Methods**"

        ''' <summary>A public method to set the MainWSFObjects</summary>
        Public Sub SetMainWSFObject(ByRef objWSFObject As dbiWSF.FrameworkObjects.objWSFObjects)
            If objWSFObject IsNot Nothing Then
                MainWSFObjects = objWSFObject
            End If
        End Sub

        ''' <summary>A public method to set the MainBusinessRules and attach
        ''' them to the global g_business rules dialog</summary>
        Public Sub SetMainBusinessRules(ByRef objBusinessRules As dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects)
            If objBusinessRules IsNot Nothing Then
                MainBusinessRules = objBusinessRules
                Me.g_BusinessRulesDialog = New dbiWSF.Dialogs.dlgBusinessRule(MainBusinessRules)
            End If
        End Sub

        ''' <summary>Sets the business rules and dbiWSFObjects then loads the data and populates the dbiSchedule</summary>
        Public Sub SetMainObjects(ByRef objWSFObject As dbiWSF.FrameworkObjects.objWSFObjects, ByRef objBusinessRules As dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects, Optional ByVal SchedStartDateTime As Date = Nothing, Optional ByVal SchedEndDateTime As Date = Nothing)
            If SchedStartDateTime = Nothing Then
                SchedStartDateTime = Today
            End If
            Me.l_SchedStartDate = SchedStartDateTime

            If SchedEndDateTime = Nothing Then
                SchedEndDateTime = Today.AddDays(7)
            End If
            Me.l_SchedEndDate = SchedEndDateTime

            Dim newSchedObj As New Dbi.WinControl.Schedule.dbiScheduleObject
            newSchedObj.Start = SchedStartDateTime
            newSchedObj.End = SchedEndDateTime
            newSchedObj.RulerAlign = Dbi.WinControl.Schedule.dbiScheduleObject.enumRulerAlign.Over
            newSchedObj.LineMinSize = 2
            newSchedObj.LineMaxSize = 4


            Me.dbiScheduleMain.Schedules.Clear()
            Me.dbiScheduleMain.Schedules.Add(newSchedObj)

            If objBusinessRules IsNot Nothing Then
                Me.SetMainBusinessRules(objBusinessRules)
            End If

            If objWSFObject IsNot Nothing Then
                MainWSFObjects = objWSFObject
                LoadData()
            End If

        End Sub

        ''' <summary>Refreshes the dbiScheduleMain based on the MainWSFObject</summary>
        ''' <remarks>If the databinding on the MaindbiWSFObjects is set to automatic then you can refresh
        ''' the schedule from other forms by calling this method. If the data is unbound then refresh the MainWSFObjects
        ''' first before calling this method.</remarks>
        Public Sub DataRefresh()
            LoadData()
        End Sub

        ''' <summary>Fills the dbiScheduleMain with data from the MainWSFObjects</summary>
        Private Sub LoadData()
            GetNodeExpansion()
            GetNodesSelected()
            Dim curSchedScroll As Long = Me.dbiScheduleMain.SchedScrollValue
            Dim curVertScroll As Long = Me.dbiScheduleMain.VertScrollValue


            Windows.Forms.Cursor.Current = Cursors.WaitCursor

            MainWSFObjects.WSFDatabinding.AutoUpdateData = True

            Me.dbiScheduleMain.Items.Clear()


            Dim x As dbiWSF.FrameworkObjects.objWarehouse
            For Each x In MainWSFObjects.Warehouses
                Dim newItem As New Dbi.WinControl.Schedule.dbiScheduleItem
                newItem.Text = x.Description
                newItem.Tag = x
                newItem.Header = True
                newItem.ReadOnly = True

                Me.dbiScheduleMain.Items.Add(newItem)
                For Each DockItem As dbiWSF.FrameworkObjects.objLoadingDock In x.LoadingDocks
                    Dim DockItemID As System.Guid = DockItem.LoadingDockID
                    Dim newChildItem As New Dbi.WinControl.Schedule.dbiScheduleItem
                    newChildItem.Text = DockItem.Description
                    newChildItem.Tag = DockItem
                    newChildItem.ImageIndex = MakeImageForLoadingDock(newChildItem)
                    newChildItem.ImageAlign = ContentAlignment.MiddleRight
                    newItem.Items.Add(newChildItem)

                    For Each GenericException As dbiWSF.FrameworkObjects.objGenericException In MainWSFObjects.GetGenericExceptionsByLoadingDock(DockItem, SchedStartDate, SchedEndDate)
                        Dim newCustomArea As New Dbi.PIM.dbiCustomArea

                        newCustomArea.DeadZone = False 'Change to True for automatic canceling
                        newCustomArea.Start = GenericException.DateStart
                        newCustomArea.End = GenericException.DateEnd

                        'Parse the exception/recurrence
                        If GenericException.objLoadingDockException IsNot Nothing Then
                            newCustomArea.BackColor = Me.ExceptionColor
                            newCustomArea.Tag = GenericException.objLoadingDockException
                        Else
                            newCustomArea.Tag = GenericException.objRecurrence
                            'Set customarea color based on recurrence type
                            Select Case GenericException.objRecurrence.RecurrenceType
                                Case FrameworkObjects.RecurrenceTypes.Daily
                                    newCustomArea.BackColor = Me.RecurrenceDailyColor
                                Case FrameworkObjects.RecurrenceTypes.Weekly
                                    newCustomArea.BackColor = Me.RecurrenceWeeklyColor
                                Case FrameworkObjects.RecurrenceTypes.Monthly
                                    newCustomArea.BackColor = Me.RecurrenceMonthlyColor
                                Case FrameworkObjects.RecurrenceTypes.Custom
                                    newCustomArea.BackColor = Me.RecurrenceCustomColor
                                Case Else
                                    newCustomArea.BackColor = Me.RecurrenceDailyColor
                            End Select
                        End If

                        newChildItem.CustomAreas.Add(newCustomArea)

                    Next



                    For Each ShipmentItem As dbiWSF.FrameworkObjects.objShipment In DockItem.Shipments
                        Dim newTimebar As New Dbi.WinControl.Schedule.dbiTimeBarItem
                        newTimebar.Start = ShipmentItem.SchedStartTime
                        newTimebar.End = ShipmentItem.SchedEndTime
                        newTimebar.Text = ShipmentItem.Description
                        newTimebar.Tag = ShipmentItem

                        If ShipmentItem.ShipmentType = dbiWSF.FrameworkObjects.ShipmentTypes.Outbound Then
                            newTimebar.BackColorTo = OutboundShipmentColor
                        End If
                        newChildItem.TimeBars.Add(newTimebar)

                    Next
                Next
            Next

            'Setup dbiWSFObjectMenu if enabled
            If dbiSchedContextMenu IsNot Nothing Then
                Me.dbiSchedContextMenu.WSFObjects = MainWSFObjects
                If Me.MainBusinessRules IsNot Nothing Then
                    Me.dbiSchedContextMenu.MyBusinessRules = MainBusinessRules
                End If
            End If

            Me.SetNodeExpansion()
            Me.SetNodesSelected()

            Me.dbiScheduleMain.VertScrollValue = curVertScroll
            Me.dbiScheduleMain.SchedScrollValue = curSchedScroll
            Me.dbiScheduleMain.TitleText = "Warehouse/Loading Dock Display All"

            Windows.Forms.Cursor.Current = Cursors.Default
        End Sub

        ''' <summary>Creates a HitTestResults object for the current mouse position.</summary>
        Public Function HitTest() As HitTestResults
            Dim curTest As New HitTestResults

            Try
                curTest.ScheduleItem = g_ScheduleItemOver
            Catch ex As Exception
                curTest.ScheduleItem = Nothing
            End Try

            Try
                If Not curTest.ScheduleItem Is Nothing Then
                    curTest.ItemIsHeader = curTest.ScheduleItem.Header
                Else
                    curTest.ItemIsHeader = False
                End If
            Catch ex As Exception
                curTest.ItemIsHeader = False
            End Try


            Try
                curTest.DateTimeAt = Me.dbiScheduleMain.DateTimeAt(g_CursorPos)
            Catch ex As Exception
                curTest.DateTimeAt = Nothing
            End Try

            If g_OverTimebar Then
                Try
                    Dim linqGetTimebars = From TimeBars As Dbi.WinControl.Schedule.dbiTimeBarItem In g_ScheduleItemOver.TimeBars _
                                          Where TimeBars.Start <= curTest.DateTimeAt And TimeBars.End >= curTest.DateTimeAt _
                                          Select TimeBars

                    curTest.TimeBarItems.AddRange(linqGetTimebars.ToArray)
                Catch ex As Exception
                    curTest.TimeBarItems.Clear()
                End Try
            Else
                curTest.TimeBarItems.Clear()
            End If

            Try
                Dim linqGetCustomAreas = From CustomAreas As Dbi.PIM.dbiCustomArea In g_ScheduleItemOver.CustomAreas _
                                         Where CustomAreas.Start <= curTest.DateTimeAt And CustomAreas.End >= curTest.DateTimeAt _
                                         Select CustomAreas
                curTest.CustomAreas.AddRange(linqGetCustomAreas.ToArray)
            Catch ex As Exception
                curTest.CustomAreas.Clear()
            End Try

            Try
                If g_CursorPos.Y < Me.dbiScheduleMain.TitleHeight And g_CursorPos.X > Me.dbiScheduleMain.ListWidth + Me.dbiScheduleMain.SplitterBarWidth + 1 Then
                    curTest.OverRuler = True
                Else
                    curTest.OverRuler = False
                End If
            Catch ex As Exception
                curTest.OverRuler = False
            End Try

            Try
                If g_CursorPos.X < Me.dbiScheduleMain.ListWidth + Me.dbiScheduleMain.SplitterBarWidth - 2 And g_CursorPos.Y > Me.dbiScheduleMain.TitleHeight Then
                    curTest.OverList = True
                Else
                    curTest.OverList = False
                End If
            Catch ex As Exception
                curTest.OverList = False
            End Try

            Return curTest

        End Function

        ''' <summary>Sets the dbiScheduleMain to a specific view and calculates the timedistance to allow
        ''' for smooth zooming.</summary>
        Public Sub SetScheduleView(ByVal ScheduleView As ScheduleViews, ByVal SchedStartDate As Date, ByVal SchedEndDate As Date, ByVal KeepCurrentPosition As Boolean)

            Dim TimeDistance As Long
            Dim TimeWidth As Long
            Dim VisibleHours As Long
            Dim VisibleDays As Long

            Dim TimeFreq As Long

            Dim CurrentVertScroll As Long

            CurrentVertScroll = Me.dbiScheduleMain.VertScrollValue

            'SchedWidth - List Width - Splitter Bar Width - Border pixels - VertScrollBar
            TimeWidth = Me.dbiScheduleMain.Width - Me.dbiScheduleMain.ListWidth - Me.dbiScheduleMain.SplitterBarWidth - 3 - 15

            'We've left the Case statements expanded as opposide to normalizing to a single function
            'to allow for easier modification of individual views.
            Select Case ScheduleView
                Case ScheduleViews.Daily05MinHourlyView
                    VisibleHours = Int(EndViewTime - StartViewTime) / 120 ' 60min * 2 as we are showing half a day
                    TimeFreq = 12

                    TimeDistance = CalcTimeDistance(ScheduleViews.Daily05MinHourlyView, VisibleHours, TimeFreq, TimeWidth)

                    Me.dbiScheduleMain.Schedules(0).TimeType = Dbi.WinControl.Schedule.enumTimeType.Hours
                    Me.dbiScheduleMain.TimeDistance = TimeDistance
                    Me.dbiScheduleMain.Schedules(0).RulerDivisions = TimeFreq


                Case ScheduleViews.Daily10MinHourlyView
                    VisibleHours = Int(EndViewTime - StartViewTime) / 120 ' 60min * 2 as we are showing half a day
                    TimeFreq = 6

                    TimeDistance = CalcTimeDistance(ScheduleViews.Daily10MinHourlyView, VisibleHours, TimeFreq, TimeWidth)

                    Me.dbiScheduleMain.Schedules(0).TimeType = Dbi.WinControl.Schedule.enumTimeType.Hours
                    Me.dbiScheduleMain.TimeDistance = TimeDistance
                    Me.dbiScheduleMain.Schedules(0).RulerDivisions = TimeFreq


                Case ScheduleViews.Daily15MinHourlyView
                    VisibleHours = Int(EndViewTime - StartViewTime) / 60 ' 60min  as we are showing full day
                    TimeFreq = 4
                    TimeDistance = CalcTimeDistance(ScheduleViews.Daily15MinHourlyView, VisibleHours, TimeFreq, TimeWidth)

                    Me.dbiScheduleMain.Schedules(0).TimeType = Dbi.WinControl.Schedule.enumTimeType.Hours
                    Me.dbiScheduleMain.TimeDistance = TimeDistance
                    Me.dbiScheduleMain.Schedules(0).RulerDivisions = TimeFreq


                Case ScheduleViews.Daily30MinHourlyView
                    VisibleHours = Int(EndViewTime - StartViewTime) / 60 ' 60min  as we are showing full day
                    TimeFreq = 2
                    TimeDistance = CalcTimeDistance(ScheduleViews.Daily30MinHourlyView, VisibleHours, TimeFreq, TimeWidth)

                    Me.dbiScheduleMain.Schedules(0).TimeType = Dbi.WinControl.Schedule.enumTimeType.Hours
                    Me.dbiScheduleMain.TimeDistance = TimeDistance
                    Me.dbiScheduleMain.Schedules(0).RulerDivisions = TimeFreq


                Case ScheduleViews.Daily60MinHourlyView
                    VisibleHours = Int(EndViewTime - StartViewTime) / 60 ' 60min  as we are showing full day
                    TimeFreq = 1
                    TimeDistance = CalcTimeDistance(ScheduleViews.Daily60MinHourlyView, VisibleHours, TimeFreq, TimeWidth)

                    Me.dbiScheduleMain.Schedules(0).TimeType = Dbi.WinControl.Schedule.enumTimeType.Hours
                    Me.dbiScheduleMain.TimeDistance = TimeDistance
                    Me.dbiScheduleMain.Schedules(0).RulerDivisions = TimeFreq


                Case ScheduleViews.Weekly1DayWeeklyView
                    VisibleDays = 7
                    TimeFreq = 12
                    TimeDistance = CalcTimeDistance(ScheduleViews.Weekly1DayWeeklyView, VisibleDays, TimeFreq, TimeWidth)
                    Me.dbiScheduleMain.Schedules(0).TimeType = Dbi.WinControl.Schedule.enumTimeType.Days

                    Me.dbiScheduleMain.TimeDistance = TimeDistance
                    Me.dbiScheduleMain.Schedules(0).RulerDivisions = TimeFreq


                Case ScheduleViews.Monthly1WeekMonthView
                    VisibleDays = 32
                    TimeFreq = 2
                    TimeDistance = CalcTimeDistance(ScheduleViews.Monthly1WeekMonthView, VisibleDays, TimeFreq, TimeWidth)

                    Me.dbiScheduleMain.Schedules(0).TimeType = Dbi.WinControl.Schedule.enumTimeType.Weeks
                    Me.dbiScheduleMain.TimeDistance = TimeDistance
                    Me.dbiScheduleMain.Schedules(0).RulerDivisions = TimeFreq

                Case ScheduleViews.Yearly1MonthYearView

                    Me.dbiScheduleMain.Schedules(0).YearFormat = Dbi.WinControl.Schedule.dbiScheduleObject.enumYearFormat.Months
                    Me.dbiScheduleMain.Schedules(0).TimeType = Dbi.WinControl.Schedule.enumTimeType.Years
                    Me.dbiScheduleMain.TimeDistance = 2
                    Me.dbiScheduleMain.Schedules(0).RulerDivisions = 1

            End Select

            Me.l_ScheduleView = ScheduleView

        End Sub
        ''' <summary>Supporting Method: Used to ensure halfday/daily/weekly/monthly/yearly 
        ''' views of the same type have the
        ''' same start and end times so the zoom is smooth</summary>
        ''' <remarks>Uses the highest common denominator value to ensure the snap to grid works for all types</remarks>
        Private Function CalcTimeDistance(ByVal ViewType As ScheduleViews, ByVal VisibleHours As Long, ByVal TimeFrequency As Long, ByVal TimeWidth As Long) As Long
            Dim TimeDistance As Long


            'The following calculation and If statement are used to assure
            'that the grid frequency flows evenly throughout the schedule.
            'If you don't ensure that the timedistance is evenly divisible to an even number
            'you may experience rounding issues with the start/end times of schedule items.
            Select Case ViewType
                Case ScheduleViews.Daily05MinHourlyView, ScheduleViews.Daily10MinHourlyView
                    TimeDistance = Int(Int(TimeWidth / VisibleHours)) - Int(Int(TimeWidth / VisibleHours)) Mod 12 ' Highest common denominator

                    If Int((TimeDistance / 12) / 2) <> (TimeDistance / 12) / 2 Then
                        TimeDistance = TimeDistance - 12
                    End If
                Case ScheduleViews.Daily15MinHourlyView, ScheduleViews.Daily30MinHourlyView, ScheduleViews.Daily60MinHourlyView
                    TimeDistance = Int(Int(TimeWidth / VisibleHours)) - Int(Int(TimeWidth / VisibleHours)) Mod 4 ' Highest common denominator

                    If Int((TimeDistance / 4) / 2) <> (TimeDistance / 4) / 2 Then
                        TimeDistance = TimeDistance - 4
                    End If
                Case ScheduleViews.Weekly1DayWeeklyView
                    TimeDistance = Int(Int(TimeWidth / VisibleHours)) - Int(Int(TimeWidth / VisibleHours)) Mod 2 ' Highest common denominator

                    If Int((TimeDistance / 2) / 2) <> (TimeDistance / 2) / 2 Then
                        TimeDistance = TimeDistance - 2
                    End If
                Case ScheduleViews.Monthly1WeekMonthView
                    TimeDistance = Int(Int(TimeWidth / VisibleHours)) - Int(Int(TimeWidth / VisibleHours)) Mod 2 ' Highest common denominator

                    If Int((TimeDistance / 2) / 2) <> (TimeDistance / 2) / 2 Then
                        TimeDistance = TimeDistance - 2
                    End If
            End Select

            Return TimeDistance

        End Function

        ''' <summary>Filters the dbiScheduleMain Items (LoadingDocks) by the cargo types passed in.</summary>
        ''' <remarks>To remove a filter pass an empty collection of CargoTypes (nothing).</remarks>
        Public Sub FilterLoadingDockCargoType(Optional ByVal CargoTypes As System.Collections.Generic.List(Of System.Guid) = Nothing)
            Me.GetNodeExpansion()
            If CargoTypes IsNot Nothing Then
                If g_IsFiltered = False Then
                    Me.g_ItemOrigColor.Clear()
                End If

                For Each dbiWhseItem As Dbi.WinControl.Schedule.dbiScheduleItem In Me.dbiScheduleMain.Items
                    If g_IsFiltered = False Then
                        Me.g_ItemOrigColor.Add(dbiWhseItem.Tag.WarehouseID, New dbiColorInfo(dbiWhseItem))
                    End If

                    For Each dbiLoadingDock As Dbi.WinControl.Schedule.dbiScheduleItem In dbiWhseItem.Items
                        If g_IsFiltered = False Then
                            Me.g_ItemOrigColor.Add(dbiLoadingDock.Tag.LoadingDockID, New dbiColorInfo(dbiLoadingDock))
                        End If
                        CalcColor(CargoTypes, dbiLoadingDock)
                    Next
                Next
                Me.dbiScheduleMain.TitleText = "Cargo Filter: "
                Me.dbiScheduleMain.TitleImage = Me.MakeImageFromCargoTypes(CargoTypes)
                Me.dbiScheduleMain.TitleBackColor = Color.AliceBlue
                g_IsFiltered = True


            Else
                g_IsFiltered = False
                Me.dbiScheduleMain.TitleImage = Nothing
                Me.dbiScheduleMain.TitleText = "Warehouse/Loading Dock Display All"
                Me.dbiScheduleMain.TitleBackColor = Color.White
                For Each dbiWarehouse As Dbi.WinControl.Schedule.dbiScheduleItem In Me.dbiScheduleMain.Items
                    Try
                        Dim curWhseColor As dbiColorInfo
                        If Me.g_ItemOrigColor.ContainsKey(dbiWarehouse.Tag.WarehouseID) Then
                            curWhseColor = Me.g_ItemOrigColor.Item(dbiWarehouse.Tag.WarehouseID)
                            If curWhseColor IsNot Nothing Then
                                dbiWarehouse.BackColor = curWhseColor.BackColor
                                dbiWarehouse.BackColorTo = curWhseColor.BackColorTo
                                dbiWarehouse.FillType = curWhseColor.FillType
                            End If
                        End If

                        For Each dbiLoadingDock As Dbi.WinControl.Schedule.dbiScheduleItem In dbiWarehouse.Items
                            Dim curLoadingDockColor As dbiColorInfo
                            If Me.g_ItemOrigColor.ContainsKey(dbiLoadingDock.Tag.LoadingDockID) Then
                                curLoadingDockColor = Me.g_ItemOrigColor.Item(dbiLoadingDock.Tag.LoadingDockID)
                                If curLoadingDockColor IsNot Nothing Then
                                    dbiLoadingDock.BackColor = curLoadingDockColor.BackColor
                                    dbiLoadingDock.BackColorTo = curLoadingDockColor.BackColorTo
                                    dbiLoadingDock.FillType = curLoadingDockColor.FillType
                                End If
                            End If
                        Next
                    Catch ex As Exception

                    End Try
                Next
            End If
            Me.dbiScheduleMain.Refresh()
        End Sub
        ''' <summary>Supporting Method:Used to calculate the backcolor of a dbiScheduleItem when the
        ''' list is filtered using the FilterLoadingDockCargoType method.</summary>
        Private Sub CalcColor(ByVal CargoTypesToCheck As System.Collections.Generic.List(Of System.Guid), _
                              ByVal LoadingDockItem As Dbi.WinControl.Schedule.dbiScheduleItem)
            Dim curLoadingDockItem As dbiWSF.FrameworkObjects.objLoadingDock = LoadingDockItem.Tag

            Dim FullMatch As Boolean = True
            Dim PartialMatch As Boolean = False

            For Each curCargoType As System.Guid In CargoTypesToCheck
                If curLoadingDockItem.CargoTypes.Contains(curCargoType) Then
                    PartialMatch = True
                Else
                    FullMatch = False
                End If
            Next

            If FullMatch Then
                LoadingDockItem.BackColor = Me.g_LoadDockColorCargoMatch

            ElseIf PartialMatch Then
                LoadingDockItem.BackColor = Me.g_LoadDockColorPartialCargoMatch

            Else
                LoadingDockItem.BackColor = Me.g_LoadDockColorNoCargoMatch

            End If
        End Sub

        ''' <summary>Returns a dbiTimeBar Item given the Shipment GUID.</summary>
        Public Function GetTimebarByShipmentID(ByVal ShipmentID As System.Guid) As Dbi.WinControl.Schedule.dbiTimeBarItem
            Dim curTimebar As Dbi.WinControl.Schedule.dbiTimeBarItem

            Dim linqTimebar = From SchedItems As Dbi.WinControl.Schedule.dbiScheduleItem In Me.dbiScheduleMain.Items _
                              From ChildItems As Dbi.WinControl.Schedule.dbiScheduleItem In SchedItems.Items _
                              From Timebars As Dbi.WinControl.Schedule.dbiTimeBarItem In ChildItems.TimeBars _
                              Where Timebars.Tag.ShipmentID = ShipmentID _
                              Select Timebars
            If linqTimebar.Count > 0 Then
                curTimebar = linqTimebar(0)
            Else
                curTimebar = Nothing
            End If

            Return curTimebar
        End Function

        ''' <summary>Returns a dbiScheduleItem given a LoadingDock GUID</summary>
        Public Function GetSchedItemByLoadingDockID(ByVal LoadingDockID As System.Guid) As Dbi.WinControl.Schedule.dbiScheduleItem
            Dim curSchedItem As Dbi.WinControl.Schedule.dbiScheduleItem

            Dim linqSchedItem = From SchedItems As Dbi.WinControl.Schedule.dbiScheduleItem In Me.dbiScheduleMain.Items _
                              From ChildItems As Dbi.WinControl.Schedule.dbiScheduleItem In SchedItems.Items _
                              Where ChildItems.Tag.LoadingDockID = LoadingDockID _
                              Select ChildItems
            If linqSchedItem.Count > 0 Then
                curSchedItem = linqSchedItem(0)
            Else
                curSchedItem = Nothing
            End If

            Return curSchedItem
        End Function

        ''' <summary>Returns a dbiScheduleItem given a Warehouse GUID</summary>
        Public Function GetSchedItemByWarehouseID(ByVal WarehouseID As System.Guid) As Dbi.WinControl.Schedule.dbiScheduleItem
            Dim curSchedItem As Dbi.WinControl.Schedule.dbiScheduleItem

            Dim linqSchedItem = From SchedItems As Dbi.WinControl.Schedule.dbiScheduleItem In Me.dbiScheduleMain.Items _
                                Where SchedItems.Tag.WarehouseID = WarehouseID _
                                Select SchedItems
            If linqSchedItem.Count > 0 Then
                curSchedItem = linqSchedItem(0)
            Else
                curSchedItem = Nothing
            End If

            Return curSchedItem
        End Function

        ''' <summary>Returns a collection of dbiCustomAreas given the LoadingDockException GUID or RecurrenceObject GUID</summary>
        Public Function GetCustomAreasByObjectID(ByVal ObjectID As System.Guid) As System.Collections.Generic.List(Of Dbi.PIM.dbiCustomArea)

            Dim curAreas As New System.Collections.Generic.List(Of Dbi.PIM.dbiCustomArea)


            For Each curWarehouse As Dbi.WinControl.Schedule.dbiScheduleItem In Me.dbiScheduleMain.Items
                For Each curLoadingDock As Dbi.WinControl.Schedule.dbiScheduleItem In curWarehouse.Items
                    For Each TestArea As Dbi.PIM.dbiCustomArea In curLoadingDock.CustomAreas
                        Select Case TestArea.Tag.GetType.ToString
                            Case GetType(dbiWSF.FrameworkObjects.objLoadingDockException).ToString
                                If TestArea.Tag.LoadingDockExceptionID = ObjectID Then
                                    curAreas.Add(TestArea)
                                End If
                            Case GetType(dbiWSF.FrameworkObjects.objRecurrence).ToString
                                If TestArea.Tag.RecurrenceID = ObjectID Then
                                    curAreas.Add(TestArea)
                                End If
                        End Select
                    Next
                Next
            Next

            Return curAreas

        End Function

        ''' <summary>Scrolls the dbiScheduleMain to the datetime of the Shipment and ensures the LoadingDock 
        ''' Schedule Item is visible in the dbiSchedule.</summary>
        ''' <remarks>This method will scroll the dbiSchedule both vertically and horizontally to ensure
        ''' the Shipment that is passed by it's GUID is visible in the schedule area of the control.</remarks>
        Public Sub ScrollToShipment(ByVal ShipmentID As System.Guid)
            Dim curTimeBar As Dbi.WinControl.Schedule.dbiTimeBarItem
            Dim curItem As Dbi.WinControl.Schedule.dbiScheduleItem
            Dim curWarehouse As Dbi.WinControl.Schedule.dbiScheduleItem
            Dim curShipment As dbiWSF.FrameworkObjects.objShipment = MainWSFObjects.GetShipmentFromGUID(ShipmentID)

            curTimeBar = Me.GetTimebarByShipmentID(curShipment.ShipmentID)
            curItem = Me.GetSchedItemByLoadingDockID(curShipment.LoadingDockID)
            curWarehouse = Me.GetSchedItemByWarehouseID(MainWSFObjects.GetLoadingDockFromGUID(curShipment.LoadingDockID).WarehouseID)
            curWarehouse.Expand()
            Me.dbiScheduleMain.EnsureVisible(curItem)
            Me.dbiScheduleMain.ScrollToDateTime(curTimeBar.Start, 0)
        End Sub

        ''' <summary>Supporting Method:Stores the tree expansion structure of the current dbiScheduleItems.</summary>
        ''' <remarks>This method is used when refreshing data from the MainWSFObject to ensure the dbiScheduleMain
        ''' returns to the same state it was in before a refresh occurs.</remarks>
        Private Sub GetNodeExpansion()
            Me.l_SchedItemsExpanded.Clear()
            For Each curNode As Dbi.WinControl.Schedule.dbiScheduleItem In Me.dbiScheduleMain.Items
                If curNode.Tag.GetType Is GetType(dbiWSF.FrameworkObjects.objWarehouse) Then
                    If curNode.IsExpanded Then
                        Me.l_SchedItemsExpanded.Add(curNode.Tag.WarehouseID)
                    End If
                End If
            Next
        End Sub

        ''' <summary>Supporting Method:Applies the existing tree expansion structure created with the GetNodeExpansion method
        ''' to the current dbiScheduleItems.</summary>
        ''' <remarks>This method is used when refreshing data from the MainWSFObject to ensure the dbiScheduleMain
        ''' returns to the same state it was in before a refresh occurs.</remarks>
        Private Sub SetNodeExpansion()
            For Each curNode As Dbi.WinControl.Schedule.dbiScheduleItem In Me.dbiScheduleMain.Items
                If curNode.Tag.GetType Is GetType(dbiWSF.FrameworkObjects.objWarehouse) Then
                    If Me.l_SchedItemsExpanded.Contains(curNode.Tag.WarehouseID) Then
                        curNode.Expand()
                    End If
                End If
            Next
        End Sub

        ''' <summary>Supporting Method:Stores the selected item structure of the dbiScheduleItems.</summary>
        ''' <remarks>This method is used when refreshing data from the MainWSFObject to ensure the dbiScheduleMain
        ''' returns to the same state it was in before a refresh occurs.</remarks>
        Private Sub GetNodesSelected()
            Me.l_SelectedWarehouseGuids.Clear()
            Me.l_SelectedLoadingDockGuids.Clear()
            For Each WarehouseNode As Dbi.WinControl.Schedule.dbiScheduleItem In Me.dbiScheduleMain.Items
                If WarehouseNode.Selected = True Then
                    Me.l_SelectedWarehouseGuids.Add(WarehouseNode.Tag.WarehouseID)
                End If
                For Each LoadingDockNode As Dbi.WinControl.Schedule.dbiScheduleItem In WarehouseNode.Items
                    If LoadingDockNode.Selected = True Then
                        Me.l_SelectedLoadingDockGuids.Add(LoadingDockNode.Tag.LoadingDockID)
                    End If
                Next
            Next
        End Sub

        ''' <summary>Supporting Method:Applies the selected item structure of the dbiScheduleItems.</summary>
        ''' <remarks>This method is used when refreshing data from the MainWSFObject to ensure the dbiScheduleMain
        ''' returns to the same state it was in before a refresh occurs.</remarks>
        Private Sub SetNodesSelected()
            For Each WarehouseNode As Dbi.WinControl.Schedule.dbiScheduleItem In Me.dbiScheduleMain.Items
                If Me.l_SelectedWarehouseGuids.Contains(WarehouseNode.Tag.WarehouseID) Then
                    WarehouseNode.Selected = True
                End If
                For Each LoadingDockNode As Dbi.WinControl.Schedule.dbiScheduleItem In WarehouseNode.Items
                    If Me.l_SelectedLoadingDockGuids.Contains(LoadingDockNode.Tag.LoadingDockID) Then
                        LoadingDockNode.Selected = True
                    End If
                Next
            Next
        End Sub

        ''' <summary>Event Handler: Handles context menu to filter the dbiScheduleMain Items by CargoType.</summary>
        Private FilterByCargoHandler As New System.EventHandler(AddressOf FilterByCargo)
        ''' <summary>Handles context menu to filter the dbiScheduleMain Items by CargoType.</summary>
        Private Sub FilterByCargo(ByVal sender As Object, ByVal e As System.EventArgs)
            Me.FilterLoadingDockCargoType(sender.tag.GetCargoTypes)
        End Sub

        ''' <summary>Event Handler: Handles context menu to clear the CargoType filter on the dbiScheduleMain.</summary>
        Private ClearFilterHandler As New System.EventHandler(AddressOf ClearFilter)
        ''' <summary>Handles context menu to clear the CargoType filter on the dbiScheduleMain.</summary>
        Private Sub ClearFilter()
            Me.FilterLoadingDockCargoType()
        End Sub

        ''' <summary>Supporting Method:Combines available cargotype icons into a single image
        ''' for use in the dbiScheduleItem for that LoadingDock.</summary>
        Private Function MakeImageForLoadingDock(ByRef curSchedItem As Dbi.WinControl.Schedule.dbiScheduleItem) As Long

            Dim curLoadingDock As dbiWSF.FrameworkObjects.objLoadingDock = curSchedItem.Tag

            Dim mainImage As Image


            Dim collCargoGuids As New System.Collections.Generic.List(Of System.Guid)

            For Each curCargoGuid As System.Guid In curLoadingDock.CargoTypes
                If Not collCargoGuids.Contains(curCargoGuid) Then
                    collCargoGuids.Add(curCargoGuid)
                End If
            Next

            If collCargoGuids.Count > 0 Then
                Dim myBitmap As New Bitmap(90, 16)
                Dim myGraphics As Graphics = Graphics.FromImage(myBitmap)
                Dim curPosition As Long = 0
                collCargoGuids.Sort()

                For Each CargoType As System.Guid In collCargoGuids
                    Dim curCargo As dbiWSF.FrameworkObjects.objCargoType = MainWSFObjects.GetCargoFromGUID(CargoType)
                    Dim curByte() As Byte = curCargo.Icon
                    Dim curImage As Image = Image.FromStream(New System.IO.MemoryStream(curByte))
                    myGraphics.DrawImage(curImage, curPosition, 0)
                    curPosition += 18
                Next

                Do While curPosition < 90
                    Dim blankImage As Image = New Bitmap(16, 16)
                    myGraphics.DrawImage(blankImage, curPosition, 0)
                    curPosition += 18
                Loop

                mainImage = myBitmap
            Else
                mainImage = New Bitmap(90, 16)
            End If

            Dim curIndex As Long
            Dim keyString As String = System.Guid.NewGuid.ToString
            Me.imagelistLoadingDockCarg.Images.Add(keyString, mainImage)
            curIndex = Me.imagelistLoadingDockCarg.Images.IndexOfKey(keyString)


            Return curIndex


        End Function

        ''' <summary>Supporting Method:Creates an image from the cargo types collection passed to the method.</summary>
        Private Function MakeImageFromCargoTypes(Optional ByVal CargoTypes As System.Collections.Generic.List(Of System.Guid) = Nothing) As Image
            Dim returnImage As Image
            Try
                If CargoTypes IsNot Nothing Then
                    Dim myBitmap As New Bitmap(18 * CargoTypes.Count, 16)
                    Dim myGraphics As Graphics = Graphics.FromImage(myBitmap)
                    Dim curPosition As Long = 0
                    CargoTypes.Sort()

                    For Each CargoType As System.Guid In CargoTypes
                        Dim curCargo As dbiWSF.FrameworkObjects.objCargoType = MainWSFObjects.GetCargoFromGUID(CargoType)
                        Dim curByte() As Byte = curCargo.Icon
                        Dim curImage As Image = Image.FromStream(New System.IO.MemoryStream(curByte))
                        myGraphics.DrawImage(curImage, curPosition, 0)
                        curPosition += 18
                    Next
                    returnImage = myBitmap
                Else
                    returnImage = New Bitmap(16, 16)
                End If
            Catch ex As Exception
                returnImage = New Bitmap(16, 16)
            End Try
            Return returnImage
        End Function

        ''' <summary>Supporting Method:Creates a dbiTipsObject for use with the dbiTips when hovering over a dbiTimeBar.</summary>
        Private Function MakeTipForTimeBar(ByRef curTimeBar As Dbi.WinControl.Schedule.dbiTimeBarItem) As Dbi.WinControl.Tips.dbiTipsObject
            'Declare a new dbiTipsObject
            Dim newTip As New Dbi.WinControl.Tips.dbiTipsObject

            'Set the default properties of the dbiTipsObject
            newTip.FillType = Dbi.enumFillType.Vertical
            newTip.HeaderVisible = True
            newTip.FooterVisible = True
            newTip.HeaderImage = My.Resources.TimeBarForTip 'Pull an image from the resources file for the header.
            newTip.HeaderFont = New Font("Trebuchet MS", 12, FontStyle.Bold, GraphicsUnit.Pixel)
            newTip.HeaderText = curTimeBar.Text
            newTip.HeaderForeColor = Color.DarkBlue

            Dim footerImage As Image

            Dim curShipment As dbiWSF.FrameworkObjects.objShipment = curTimeBar.Tag

            If curShipment.BreakoutDockQty <= 0 Then
                'If there are no breakout docks needed then tip is blue
                newTip.BackColor = Color.White
                'Make a blue fade effect for non-breakout dock tips.
                newTip.BackColorTo = Color.FromArgb(228, 239, 239)
            Else
                'If there are breakout docks then tip is red
                newTip.BackColor = Color.White
                'Make a red fade effect for breakout dock tips.
                newTip.BackColorTo = Color.FromArgb(255, 209, 208)
            End If


            If curShipment.GetCargoTypes.Count > 0 Then

                footerImage = MakeImageFromCargoTypes(curShipment.GetCargoTypes)
                newTip.FooterImage = footerImage
                newTip.FooterText = "Cargo Types in Shipment"
                newTip.FooterFont = New Font("Trebuchet MS", 12, FontStyle.Italic + FontStyle.Bold, GraphicsUnit.Pixel)
                newTip.FooterForeColor = Color.DarkBlue
                Me.dbiTipsMain.FooterLine = True
            Else
                newTip.FooterVisible = False
                Me.dbiTipsMain.FooterLine = False
            End If

            Dim bodyString As String
            bodyString = "Start: " + curTimeBar.Start.ToString _
            + vbCrLf + "End: " + curTimeBar.End.ToString + vbCrLf

            If curShipment.BreakoutDockQty > 0 Then
                bodyString += vbCrLf + "**Breakout docks required: " + curShipment.BreakoutDockQty.ToString + vbCrLf
            End If

            bodyString += vbCrLf

            If curShipment.OrderHeaders.Count > 0 Then
                bodyString += "Orders on this shipment:" + vbCrLf
            Else
                bodyString += "There are no orders on this shipment." + vbCrLf
            End If

            For Each curOrderHeader As dbiWSF.FrameworkObjects.objOrderHeader In curShipment.OrderHeaders
                bodyString += curOrderHeader.OrderEntryType + ": " + curOrderHeader.OrderEntryID + vbCrLf
            Next

            newTip.BodyFont = New Font("Trebuchet MS", 12, FontStyle.Regular, GraphicsUnit.Pixel)
            newTip.BodyText = bodyString
            newTip.BodyForeColor = Color.Black

            Return newTip

        End Function

        ''' <summary>Supporting Method:Creates a dbiTipsObject for use with the dbiTips when hovering over a dbiListItem.</summary>
        Public Function MakeTipForCargoTip() As Dbi.WinControl.Tips.dbiTipsObject

            Dim lineFont As New Font("Trebuchet MS", 10, FontStyle.Regular, GraphicsUnit.Point)
            Dim headerFont As New Font(lineFont, FontStyle.Bold + FontStyle.Italic)
            Dim lineSize As New Size(0, 0)
            Dim lineFormat As New StringFormat
            Dim curPos As Integer = 22

            Dim imgHeight As Integer = 20 + (20 * MainWSFObjects.CargoTypes.Count)
            Dim maxWidth As Integer = 180

            'Get MaxStringWidth
            Dim tempBitmap As New Bitmap(600, 40)

            Dim tempGraphics As Graphics = Graphics.FromImage(tempBitmap)


            For Each cargoStr As dbiWSF.FrameworkObjects.objCargoType In MainWSFObjects.CargoTypes.Values
                If tempGraphics.MeasureString(cargoStr.Description, lineFont, lineSize, lineFormat).Width > maxWidth Then
                    maxWidth = tempGraphics.MeasureString(cargoStr.Description, lineFont, lineSize, lineFormat).Width
                End If
            Next
            maxWidth += 20

            Dim liveBitmap As New System.Drawing.Bitmap(maxWidth, imgHeight)
            Dim liveGraphics As Graphics = Graphics.FromImage(liveBitmap)

            liveGraphics.Clear(Color.AliceBlue)
            liveGraphics.DrawString("Available Cargo Types", headerFont, Brushes.Navy, 2, 2)
            liveGraphics.DrawRectangle(Pens.Navy, New Rectangle(0, 0, liveBitmap.Width - 1, liveBitmap.Height - 1))

            Dim linqColl = From cargoItem As dbiWSF.FrameworkObjects.objCargoType In MainWSFObjects.CargoTypes.Values _
                           Select cargoItem.CargoID _
                           Order By CargoID Ascending



            For Each curCargoID As System.Guid In linqColl


                Dim curByte() As Byte = MainWSFObjects.GetCargoFromGUID(curCargoID).Icon
                Dim curImage As Image = Image.FromStream(New System.IO.MemoryStream(curByte))
                liveGraphics.DrawImage(curImage, 2, curPos)
                liveGraphics.DrawString(MainWSFObjects.GetCargoFromGUID(curCargoID).Description, lineFont, Brushes.Navy, 20, curPos)
                curPos += 18
            Next
            Dim newTip As New Dbi.WinControl.Tips.dbiTipsObject
            newTip.ImageOnly = True
            newTip.HeaderVisible = False
            newTip.FooterVisible = False
            newTip.BodyImage = liveBitmap
            Return newTip
        End Function

        ''' <summary>Supporting Method:Gets the cargo GUID from a cargoType object.</summary>
        Private Function GetCargoGuidKey(ByVal curCargo As dbiWSF.FrameworkObjects.objCargoType) As String
            Return curCargo.CargoID.ToString
        End Function

#End Region

#Region "**dbiScheduleMain Event Methods**"
        'These methods handle the events of the dbiScheduleMain then raise public events
        'if needed. For more information on the events see the dbiWSF.CHM help file or the
        'dbiSchedule.CHM help file.

        Private Sub dbiScheduleMain_AfterTimeBarInserted(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.AfterTimeBarInsertedEventArgs) Handles dbiScheduleMain.AfterTimeBarInserted
            Dim ShipmentArgs As New ScheduleArgs

            ShipmentArgs.argWSFObject = Me.MainWSFObjects

            ShipmentArgs.argDbiTimebar = e.TimeBarItem
            ShipmentArgs.argDbiSchedItem = e.ScheduleItem

            If e.TimeBarItem.Tag Is Nothing Then
                Dim newShipment As New dbiWSF.FrameworkObjects.objShipment(Me.MainWSFObjects)
                newShipment.ShipmentID = System.Guid.NewGuid
                newShipment.SchedStartTime = e.TimeBarItem.Start
                newShipment.SchedEndTime = e.TimeBarItem.End
                newShipment.LoadingDockID = e.ScheduleItem.Tag.LoadingDockID
                ShipmentArgs.argDbiTimebar.Tag = newShipment
            End If
            ShipmentArgs.argShipment = ShipmentArgs.argDbiTimebar.Tag

            ShipmentArgs.argLoadingDock = e.ScheduleItem.Tag

            ShipmentArgs.argWarehouse = Me.MainWSFObjects.GetWarehouseFromGUID(e.ScheduleItem.Tag.WarehouseID)


            RaiseEvent clShipmentBeforeAdd(Me, ShipmentArgs)

            If ShipmentArgs.Allow Then
                ShipmentArgs.argShipment.AddNew(ShipmentArgs.argLoadingDock)
                If Me.BusinessRulesOnShipmentAdd Then
                    g_EventArg = ShipmentArgs
                    g_EventArgMethod = Dialogs.EventMethods.dbiSchedule_AfterTimeBarInserted
                    'Fire Timer To Validate the business rules
                    Me.timerEventSynch.Enabled = True
                Else
                    RaiseEvent clShipmentAfterAdd(Me, ShipmentArgs)
                End If
            Else
                ShipmentArgs.argDbiSchedItem.TimeBars.Remove(ShipmentArgs.argDbiTimebar)
            End If

        End Sub

        Private Sub dbiScheduleMain_BeforeTimeBarMove(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.BeforeTimeBarMoveEventArgs) Handles dbiScheduleMain.BeforeTimeBarMove
            Dim ShipmentMoveArgs As New ScheduleArgsShipmentMove

            If Not e.ScheduleItemTo Is Nothing Then
                'Transfer loading dock
                ShipmentMoveArgs.argIsShipmentLoadingDockTransfer = True
                ShipmentMoveArgs.argShipmentLoadingDockTransferTo = e.ScheduleItemTo.Tag
                ShipmentMoveArgs.argDbiSchedItemTo = e.ScheduleItemTo
            Else
                ShipmentMoveArgs.argIsShipmentLoadingDockTransfer = False
            End If

            With ShipmentMoveArgs
                .argDbiSchedItem = e.ScheduleItemFrom
                .argDbiTimebar = e.TimeBarItem
                .argLoadingDock = e.ScheduleItemFrom.Tag
                .argShipment = e.TimeBarItem.Tag
                .argWarehouse = MainWSFObjects.GetWarehouseFromGUID(.argLoadingDock.WarehouseID)
                .argWSFObject = MainWSFObjects
                .argOrigStart = e.TimeBarItem.Start
                .argOrigEnd = e.TimeBarItem.End
            End With

            With ShipmentMoveArgs.argShipment
                .SchedStartTime = e.Start
                .SchedEndTime = e.End
                If ShipmentMoveArgs.argIsShipmentLoadingDockTransfer Then
                    .LoadingDockID = ShipmentMoveArgs.argShipmentLoadingDockTransferTo.LoadingDockID
                End If
            End With

            RaiseEvent clShipmentBeforeChange(Me, ShipmentMoveArgs)

            If ShipmentMoveArgs.Allow Then
                If Me.BusinessRulesOnShipmentChange Then
                    g_EventArg = ShipmentMoveArgs
                    g_EventArgMethod = Dialogs.EventMethods.dbiSchedule_BeforeTimeBarMove
                    'Fire Timer To Validate the business rules
                    Me.timerEventSynch.Enabled = True
                End If
            Else
                ShipmentMoveArgs.argShipment.SchedStartTime = e.TimeBarItem.Start
                ShipmentMoveArgs.argShipment.SchedEndTime = e.TimeBarItem.End
                ShipmentMoveArgs.argShipment.LoadingDockID = ShipmentMoveArgs.argLoadingDock.LoadingDockID
                e.AllowMove = False
            End If

        End Sub

        Private Sub dbiScheduleMain_BeforeTimeBarSize(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.BeforeTimeBarSizeEventArgs) Handles dbiScheduleMain.BeforeTimeBarSize
            Dim ShipmentMoveArgs As New ScheduleArgsShipmentMove

            ShipmentMoveArgs.argIsShipmentLoadingDockTransfer = False

            With ShipmentMoveArgs
                .argDbiSchedItem = e.ScheduleItem
                .argDbiTimebar = e.TimeBarItem
                .argLoadingDock = e.ScheduleItem.Tag
                .argShipment = e.TimeBarItem.Tag
                .argWarehouse = MainWSFObjects.GetWarehouseFromGUID(.argLoadingDock.WarehouseID)
                .argWSFObject = MainWSFObjects
                .argOrigStart = e.TimeBarItem.Start
                .argOrigEnd = e.TimeBarItem.End
            End With

            With ShipmentMoveArgs.argShipment
                .SchedStartTime = e.Start
                .SchedEndTime = e.End
            End With

            RaiseEvent clShipmentBeforeChange(Me, ShipmentMoveArgs)

            If ShipmentMoveArgs.Allow Then
                If Me.BusinessRulesOnShipmentChange Then
                    g_EventArg = ShipmentMoveArgs
                    g_EventArgMethod = Dialogs.EventMethods.dbiSchedule_BeforeTimeBarSize
                    'Fire Timer To Validate the business rules
                    Me.timerEventSynch.Enabled = True
                End If
            Else
                ShipmentMoveArgs.argShipment.SchedStartTime = e.TimeBarItem.Start
                ShipmentMoveArgs.argShipment.SchedEndTime = e.TimeBarItem.End
                e.AllowSize = False
            End If


        End Sub

        Private Sub dbiScheduleMain_BeforeTimeBarRemove(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.BeforeTimeBarRemoveEventArgs) Handles dbiScheduleMain.BeforeTimeBarRemove
            Dim ShipmentArgs As New ScheduleArgs

            ShipmentArgs.argWSFObject = Me.MainWSFObjects

            ShipmentArgs.argDbiTimebar = e.TimeBarItem
            ShipmentArgs.argDbiSchedItem = e.ScheduleItem

            ShipmentArgs.argShipment = e.TimeBarItem.Tag
            ShipmentArgs.argLoadingDock = e.ScheduleItem.Tag
            ShipmentArgs.argWarehouse = Me.MainWSFObjects.GetWarehouseFromGUID(e.ScheduleItem.Tag.WarehouseID)

            RaiseEvent clShipmentBeforeRemove(Me, ShipmentArgs)

            If ShipmentArgs.Allow Then
                g_EventArg = ShipmentArgs
                g_EventArgMethod = Dialogs.EventMethods.dbiSchedule_BeforeTimeBarRemove
                Me.timerEventSynch.Enabled = True
            Else
                e.AllowRemoval = False
            End If
        End Sub

        Private Sub dbiScheduleMain_ItemMouseOver(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.ItemMouseOverEventArgs) Handles dbiScheduleMain.ItemMouseOver
            g_ScheduleItemOver = e.ScheduleItem
            If e.TimeBarItem Is Nothing Then
                g_OverTimebar = False
                Me.dbiTipsMain.Hide()

            Else
                g_OverTimebar = True
                If TipsOnTimebarOver Then
                    Me.dbiTipsMain.ImageOnly = False
                    Dim curTip As Dbi.WinControl.Tips.dbiTipsObject = MakeTipForTimeBar(e.TimeBarItem)
                    Me.dbiTipsMain.Show(curTip)
                End If
            End If


        End Sub

        Private Sub dbiScheduleMain_ListClick(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.ListClickEventArgs) Handles dbiScheduleMain.ListClick
            If e.ScheduleItem IsNot Nothing Then
                Select Case e.ScheduleItem.Tag.GetType.ToString
                    Case GetType(dbiWSF.FrameworkObjects.objWarehouse).ToString
                        Dim curArgs As New dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs
                        curArgs.argDbiSchedItem = e.ScheduleItem
                        curArgs.argWarehouse = e.ScheduleItem.Tag
                        curArgs.argWSFObject = MainWSFObjects
                        RaiseEvent clWarehouseClick(Me, curArgs)

                    Case GetType(dbiWSF.FrameworkObjects.objLoadingDock).ToString
                        Dim curArgs As New dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs
                        curArgs.argDbiSchedItem = e.ScheduleItem
                        curArgs.argLoadingDock = e.ScheduleItem.Tag
                        curArgs.argWarehouse = MainWSFObjects.GetWarehouseFromGUID(curArgs.argLoadingDock.WarehouseID)
                        curArgs.argWSFObject = MainWSFObjects
                        RaiseEvent clLoadingDockClick(Me, curArgs)
                End Select
            End If
        End Sub

        Private Sub dbiScheduleMain_ListDoubleClick(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.ListDoubleClickEventArgs) Handles dbiScheduleMain.ListDoubleClick
            If e.ScheduleItem IsNot Nothing Then
                Select Case e.ScheduleItem.Tag.GetType.ToString
                    Case GetType(dbiWSF.FrameworkObjects.objWarehouse).ToString
                        Dim whseArgs As New dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs
                        whseArgs.argWarehouse = e.ScheduleItem.Tag
                        whseArgs.argWSFObject = MainWSFObjects
                        whseArgs.argDbiSchedItem = e.ScheduleItem
                        RaiseEvent clWarehouseDoubleClick(Me, whseArgs)
                    Case GetType(dbiWSF.FrameworkObjects.objLoadingDock).ToString
                        Dim loadingdockArgs As New dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs
                        loadingdockArgs.argDbiSchedItem = e.ScheduleItem
                        loadingdockArgs.argLoadingDock = e.ScheduleItem.Tag
                        loadingdockArgs.argWSFObject = MainWSFObjects
                        loadingdockArgs.argWarehouse = MainWSFObjects.GetWarehouseFromGUID(loadingdockArgs.argLoadingDock.WarehouseID)
                        RaiseEvent clLoadingDockDoubleClick(Me, loadingdockArgs)
                End Select
            End If
        End Sub

        Private Sub dbiScheduleMain_ListWidthChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dbiScheduleMain.ListWidthChanged
            If Me.dbiScheduleMain.ListWidth < 252 Then
                Me.dbiScheduleMain.ListWidth = 252
            End If
        End Sub

        Private Sub dbiScheduleMain_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dbiScheduleMain.MouseClick

            RaiseEvent SchedClick(Me.dbiScheduleMain, e, HitTest)
            If e.Button = Windows.Forms.MouseButtons.Right Then
                If HitTest.DisplayMenu = True Then
                    If dbiSchedContextMenu IsNot Nothing Then

                        Me.dbiSchedContextMenu.BuildMenu(HitTest)

                        If HitTest.TimeBarItems IsNot Nothing And HitTest.TimeBarItems.Count > 0 Then
                            Dim Divide As New System.Windows.Forms.ToolStripSeparator
                            Me.dbiSchedContextMenu.Items.Add(Divide)
                            Dim menuitemFilter As System.Windows.Forms.ToolStripMenuItem
                            menuitemFilter = Me.dbiSchedContextMenu.Items.Add("Filter by: " + HitTest.TimeBarItems(0).Tag.Description + " Cargo Types", Nothing, FilterByCargoHandler)
                            menuitemFilter.Tag = HitTest.TimeBarItems(0).Tag
                        End If

                        If HitTest.OverList And g_IsFiltered Then
                            Dim Divide As New System.Windows.Forms.ToolStripSeparator
                            Me.dbiSchedContextMenu.Items.Add(Divide)
                            Dim menuitemClearFilter As System.Windows.Forms.ToolStripMenuItem
                            menuitemClearFilter = Me.dbiSchedContextMenu.Items.Add("Clear Loading Dock Filters", Nothing, ClearFilterHandler)
                        End If

                        Me.dbiSchedContextMenu.Show(Windows.Forms.Cursor.Position)
                    End If
                End If
            End If
        End Sub

        Private Sub dbiScheduleMain_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dbiScheduleMain.MouseMove
            g_CursorPos = e.Location

            If (g_CursorPos.X < Me.dbiScheduleMain.ListWidth And g_CursorPos.X > 0) And (g_CursorPos.Y < Me.dbiScheduleMain.TitleHeight And g_CursorPos.Y > 0) Then
                RaiseEvent clTitleOver(Me, e)
                If TipsOnTitleOver Then
                    If MainWSFObjects IsNot Nothing Then
                        If MainWSFObjects.CargoTypes IsNot Nothing Then
                            If MainWSFObjects.CargoTypes.Count > 0 Then
                                If Not g_OverTitleTipDisplay Then
                                    g_OverTitleTipDisplay = True
                                    Dim newCargoTip As Dbi.WinControl.Tips.dbiTipsObject = MakeTipForCargoTip()
                                    dbiTipsTitle.Show(newCargoTip)
                                End If
                            End If
                        End If
                    End If
                End If
            Else
                g_OverTitleTipDisplay = False
                Me.dbiTipsTitle.Hide()
            End If

        End Sub

        Private Sub dbiScheduleMain_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles dbiScheduleMain.LostFocus
            Me.dbiTipsMain.Hide()
        End Sub

        Private Sub dbiScheduleMain_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles dbiScheduleMain.MouseLeave
            Me.dbiTipsMain.Hide()
        End Sub

        Private Sub dbiScheduleMain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dbiScheduleMain.Click
            Me.dbiScheduleMain.SelectedBackColor = Color.FromArgb(80, Me.dbiScheduleMain.SelectedBackColor)

        End Sub

        Private Sub dbiScheduleMain_UserDrawnBar(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.UserDrawnBarEventArgs) Handles dbiScheduleMain.UserDrawnBar
            RaiseEvent clUserDrawnBar(sender, e)
        End Sub

        Private Sub dbiScheduleMain_UserDrawnFooter(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.UserDrawnFooterEventArgs) Handles dbiScheduleMain.UserDrawnFooter
            RaiseEvent clUserDrawnFooter(sender, e)
        End Sub

        Private Sub dbiScheduleMain_UserDrawnHeader(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.UserDrawnHeaderEventArgs) Handles dbiScheduleMain.UserDrawnHeader
            RaiseEvent clUserDrawnHeader(sender, e)
        End Sub

        Private Sub dbiScheduleMain_UserDrawnLine(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.UserDrawnLineEventArgs) Handles dbiScheduleMain.UserDrawnLine
            RaiseEvent clUserDrawnLine(sender, e)
        End Sub

        Private Sub dbiScheduleMain_AfterTimeBarDrop(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.AfterTimeBarDropEventArgs) Handles dbiScheduleMain.AfterTimeBarDrop
            RaiseEvent clAfterTimeBarDrop(sender, e)
        End Sub

        Private Sub dbiScheduleMain_BeforeTimeBarDrop(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.BeforeTimeBarDropEventArgs) Handles dbiScheduleMain.BeforeTimeBarDrop
            RaiseEvent clBeforeTimeBarDrop(sender, e)
        End Sub

        Private Sub dbiScheduleMain_DropList(ByVal sender As Object, ByVal e As Dbi.WinControl.DropListEventArgs) Handles dbiScheduleMain.DropList
            RaiseEvent clDropList(sender, e)
        End Sub

        Private Sub dbiScheduleMain_ValuePoint(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.ValuePointEventArgs) Handles dbiScheduleMain.ValuePoint
            RaiseEvent clValuePoint(sender, e)
        End Sub

        Private Sub dbiScheduleMain_TimeBarDoubleClick(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.TimeBarDoubleClickEventArgs) Handles dbiScheduleMain.TimeBarDoubleClick
            Dim SchedArgs As New ScheduleArgs
            With SchedArgs
                .argWSFObject = MainWSFObjects
                .argDbiSchedItem = e.ScheduleItem
                .argDbiTimebar = e.TimeBarItem
                .argShipment = e.TimeBarItem.Tag
                .argLoadingDock = e.ScheduleItem.Tag
                .argWarehouse = .argWSFObject.GetWarehouseFromGUID(.argLoadingDock.WarehouseID)
            End With
            RaiseEvent clShipmentDoubleClick(Me, SchedArgs)
        End Sub

#End Region

#Region "**Events/Methods for the BusinessRules dialog**"
        ''' <summary>Calls the business rules dialog after a shipment has changed.</summary>
        Public Sub evntClShipmentAfterChanged(ByVal sender As Object, ByVal ShipmentMoveArgs As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgsShipmentMove)
            RaiseEvent clShipmentAfterChange(Me, ShipmentMoveArgs)
        End Sub
        ''' <summary>Calls the business rules dialog after a shipment has been removed.</summary>
        Public Sub evntClShipmentAfterRemove(ByVal sender As Object, ByVal ShipmentArgs As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs)
            RaiseEvent clShipmentAfterRemove(Me, ShipmentArgs)
        End Sub
        ''' <summary>Calls the business rules dialog after a shipment has been added.</summary>
        Public Sub evntClShipmentAfterAdd(ByVal sender As Object, ByVal ShipmentArgs As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs)
            RaiseEvent clShipmentAfterAdd(Me, ShipmentArgs)
        End Sub

        ''' <summary>Supporting Method:Used to call the business rules dialog from an internal timer.</summary>
        ''' <remarks>This is done so that we do not halt internal events from firing within
        ''' the dbiSchedule control which can have undesireable effects.</remarks>
        Private Sub timerEventSynch_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerEventSynch.Tick
            Me.timerEventSynch.Enabled = False
            g_BusinessRulesDialog.StartProcess(g_EventArg, g_EventArgMethod, Me)
            Me.dbiScheduleMain.Refresh()
        End Sub
#End Region

#Region "**dbiSched Context Menu methods/events**"
        ''' <summary>Refreshes the dbiScheduleMain if a context menu updates any 
        ''' underlying objects in the MainWSFObjects.</summary>
        Private Sub dbiSchedContextMenu_ContextMenuUpdatedData(ByVal sender As Object, ByVal e As System.EventArgs) Handles l_dbiSchedContextMenu.cmUpdatedData
            Me.DataRefresh()
        End Sub
#End Region

    End Class

End Namespace

